﻿/*
 * @File: BillingBLL.cs
 * @in namespace: BLL
 */

using System;
using DAL;

/// <summary>
/// Summary description for BillingBLL
/// </summary>
namespace BLL
{
    public class BillingBLL
    {
        public BillingBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IBilling Members

        /// <summary>
        /// GetBillingByUserID
        /// </summary>
        /// <param name="userID">User ID</param>
        /// <returns>records corresponding</returns>
        public static Billing[] GetBillingByUserID(int userID)
        {
            try
            {
                return DataAccessHelper.GetBillingDA().GetBillingByUserID(userID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetBillingByBillID
        /// </summary>
        /// <param name="billID"Bill ID</param>
        /// <returns>records corresponding</returns>
        public static Billing GetBillingByBillID(int billID)
        {
            try
            {
                return DataAccessHelper.GetBillingDA().GetBillingByBillID(billID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// InsertBilling
        /// </summary>
        /// <param name="billing">Billing Entity</param>
        /// <param name="autoNumber">BillID output</param>
        /// <returns>1 if successful, 0 if error</returns>
        public static int InsertBilling(Billing billing, out int autoNumber)
        {
            try
            {
                if (billing.UserID == 0)
                    throw new OnlineFloralDeliveryException(2, "UserID is not allow null or empty");
                if (billing.TotalAmount == 0)
                    throw new OnlineFloralDeliveryException(2, "TotalAmount is not allow null or empty");

                return DataAccessHelper.GetBillingDA().InsertBilling(billing, out autoNumber);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// UpdateBilling
        /// </summary>
        /// <param name="billing">Billing Entity</param>
        /// <returns>1 if successful, 0 if error</returns>
        public static int UpdateBilling(Billing billing)
        {
            try
            {
                if (billing.BillID == 0)
                    throw new OnlineFloralDeliveryException(2, "BillID is not allow null or empty");
                if (billing.BillDate == null)
                    throw new OnlineFloralDeliveryException(2, "BillDate is not allow null or empty");

                return DataAccessHelper.GetBillingDA().UpdateBilling(billing);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}